require "rss_reader"

class RssChannel < ActiveRecord::Base
	belongs_to :user

	validates_presence_of     :url
	#validates_format_of :url, :with => /^((http|https):\/\/)*[a-z0-9_-]{1,}\.*[a-z0-9_-]{1,}\.[a-z]{2,4}\/*$/i
=begin
  def validate
    errors.add(:url, "unexistent") unless RssChannel.existent_url?(:url)
  end

  def self.existent_url?(url)
    uri = URI.parse(url)
    http_conn = Net::HTTP.new(uri.host, uri.port)
    resp, data = http_conn.head("/" , nil)
    resp.code.to_i == 200
  end
=end

	def post
		RssPostReader.parse_url(self.url, 5)
	end
end
